/**
AirwayPathfinder for X-Plane Flight Simulator. Calculates the shortest path between two NavAids. 
Copyright (C) 2011  Nils Buletta

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 **/

package de.buletta.airwaypathfinder;

import java.awt.Graphics2D;
import org.jdesktop.swingx.JXMapViewer;
import org.jdesktop.swingx.mapviewer.Waypoint;
import org.jdesktop.swingx.mapviewer.WaypointRenderer;

/**
 * Renders the Waypoints
 * 
 * @author Nils Buletta
 * @version 0.1
 */
public class NavsRenderer implements WaypointRenderer {
	private boolean showNoAirwayNav = true;

	public NavsRenderer() {
		super();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.jdesktop.swingx.mapviewer.WaypointRenderer#paintWaypoint(java.awt
	 * .Graphics2D, org.jdesktop.swingx.JXMapViewer,
	 * org.jdesktop.swingx.mapviewer.Waypoint)
	 */
	@Override
	public boolean paintWaypoint(Graphics2D g, JXMapViewer map, Waypoint wp) {
		if (wp instanceof EarthNav) {
			// if(((EarthNav)wp).getIdentifier().equals("TSU")) {
			// System.out.println("TSU");
			// }
			if (showNoAirwayNav || ((EarthNav) wp).getConnections().size() > 0) {
				switch (((EarthNav) wp).getType()) {
				case 2:
					g.drawArc(-5, -5, 9, 9, 360, 360);
					if (map.getZoom() <= 9)
						g.drawString(((EarthNav) wp).getIdentifier(), 7, 5);

					return true;
				case 3:
					g.drawLine(-2, 5, 2, 5);// lower line
					g.drawLine(-2, -5, 2, -5);// upper line
					g.drawLine(-2, 5, -5, 0);// left side
					g.drawLine(-5, 0, -2, -5);// left side
					g.drawLine(2, 5, 5, 0);// right side
					g.drawLine(5, 0, 2, -5);// right side
					if (map.getZoom() <= 9)
						g.drawString(((EarthNav) wp).getIdentifier(), 7, 5);

					return true;
				case 11:
					g.drawLine(-5, 5, 5, 5);
					g.drawLine(0, -5, -5, 5);
					g.drawLine(0, -5, 5, 5);
					if (map.getZoom() <= 9)
						g.drawString(((EarthNav) wp).getIdentifier(), 7, 5);

					return true;
				}
			}
		}

		return false;
	}

	public void setShowNoAirwayNav(boolean b) {
		this.showNoAirwayNav = b;
	}

}
